package map;

import java.util.HashMap;
import java.util.Map;

public class leedcode914卡牌分组 {
    public static void main(String[] args) {
        int[] arr = {1,2,1,2,3};
        System.out.println(hasGroupsSizeX(arr));
        System.out.println(maxYS(2,4));
    }

    public static boolean hasGroupsSizeX(int[] deck) {
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i < deck.length;i++ ){
            int val = 0;
            if(!map.containsKey(deck[i])){
                val = map.getOrDefault(deck[i], 0) + 1;
                map.put(deck[i],val);
            }else {
                Integer integer = map.get(deck[i]);
                map.put(deck[i] , integer+1);
            }
        }
        int integer = map.get(deck[0]);
        for (Map.Entry<Integer, Integer> m:map.entrySet()) {
            if (m.getValue() < 1){
                return false;
            }
            if (maxYS(integer,m.getValue()) == 1){
                return false;
            }
            integer = m.getValue();
        }
        return true;
    }
    public static int maxYS(int num1,int num2){
        return num1 % num2 == 0 ? num2 : maxYS(num2,num1 % num2);
    }
}
